{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}

module MultiSet.List (ListMultiSet) where

import MultiSet.Class

import Data.List (delete)

instance MultiSet1 [] where
  member1 x s  = x `elem` s
  empty1       = []
  insert1 x s  = x:s
  arb1 s       = head s
  without1 s x = delete x s
  isEmpty1 s   = null s

instance (Eq a) => MultiSet [] a where
  member x s  = x `elem` s
  empty       = []
  insert x s  = x:s
  arb s       = head s
  without s x = delete x s
  isEmpty s   = null s

newtype ListMultiSet a = ListMultiSet [a]

instance (Eq a) => MultiSet ListMultiSet a where
  member x (ListMultiSet s)  = x `elem` s
  empty                      = ListMultiSet []
  insert x (ListMultiSet s)  = ListMultiSet (x:s)
  arb (ListMultiSet s)       = head s
  without (ListMultiSet s) x = ListMultiSet (delete x s)
  isEmpty (ListMultiSet s)   = null s
